#include<bits/stdc++.h>
#define int int64_t
using namespace std;
int T,x,sum,ans;
set<int>s;
bool typ;
int32_t main(){
	freopen("kte.in","r",stdin),freopen("kte.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cin>>T,typ=(T<=1000);
	while(T--){
		cin>>x,ans=0;
		if(!s.count(x))
			s.emplace(x),sum+=x;
		else
			s.erase(x),sum-=x;
		if(s.empty())
			cout<<"0\n";
		else if(typ||s.size()<=15){
			auto it1=s.begin(),it2=prev(s.end());
			for(int i=1,l=0,r=0,lst=0;i<=(int)s.size();i++){
				l+=*it1,r+=*it2,ans+=r-max(l,lst),lst=r;
				if(i!=(int)s.size())
					it1++,it2--;
			}
			cout<<ans<<'\n';
		}
		else
			cout<<sum-(*s.begin()<<1)<<'\n';
	}
	return 0;
}